# -*- coding: utf-8 -*-
# !/usr/bin/env python

from channels.generic.websocket import AsyncJsonWebsocketConsumer
from components.deploy.k8s_release.dao import get_download_event
from utils.views import SResult


class DownloadEvent(AsyncJsonWebsocketConsumer):
    async def connect(self):
        await self.accept()

    async def disconnect(self, close_code):
        pass

    async def receive_json(self, data_json, **kwargs):

        if not data_json:
            await self.send_json(SResult.error('空数据请求'), True)
            return

        message = await get_download_event(data_json['download_event_ids'], True, data_json['download_event_type'])

        await self.send_json(SResult.success(message))

